package com.zone.vehicle.superapp.view.home.detail.adapter;

import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.youth.banner.adapter.BannerAdapter;
import com.zone.vehicle.lib.view.utils.ImageUtil;

import java.util.List;

/**
 * @Author: pkqlqx
 * @CreateDate: 2022/2/25 17:40
 * @Description:
 */
public class ImageAdapter extends BannerAdapter<String, ImageAdapter.BannerViewHolder> {

    private List<String> mList;
    private FragmentActivity fragmentActivity;

    public ImageAdapter(List<String> mDatas, FragmentActivity activity) {
        //设置数据，也可以调用banner提供的方法,或者自己在adapter中实现
        super(mDatas);
        this.mList = mDatas;
        this.fragmentActivity = activity;
    }

    //创建ViewHolder，可以用viewType这个字段来区分不同的ViewHolder
    @Override
    public BannerViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = new ImageView(parent.getContext());
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return new BannerViewHolder(imageView);
    }

    @Override
    public void onBindView(BannerViewHolder holder, String data, int position, int size) {
//        holder.imageView.setImageResource(data);
//        RoundedCorners roundedCorners = new RoundedCorners(50);
//        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners)
//                .placeholder(new ColorDrawable(Color.GRAY));//设置占位图
//        Glide.with(fragmentActivity)
//                .asBitmap().load(mList.get(position))
//                .apply(options).into((ImageView) holder.itemView);
        ImageUtil.load(holder.itemView.getContext(), (ImageView) holder.itemView, mList.get(position));
    }

    class BannerViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;

        public BannerViewHolder(@NonNull ImageView view) {
            super(view);
            this.imageView = view;
        }
    }
}